#include "image_button.h"

image_button::image_button(const char *image, int x, int y, int w, int h, const char *cache):m_path(cache)
{
    m_image = SDL_LoadBMP(image);
    m_rect = {x, y, w, h};
    m_clicked = 0;
}

int image_button::click(int x, int y)
{
    if(m_rect.x <= x && x < m_rect.x + m_rect.w && m_rect.y <= y && y < m_rect.y + m_rect.h){
        m_clicked = !m_clicked;
        return 1;
    }

    return 0;
}

int image_button::clicked()
{
    return m_clicked;
}

int image_button::reset()
{
    int ret = m_clicked;
    m_clicked = 0;

    return ret;
}

void image_button::draw(SDL_Renderer *renderer)
{
    SDL_Texture *image = SDL_CreateTextureFromSurface(renderer, m_image);
    SDL_RenderCopy(renderer, image, NULL, &m_rect);
}

const char* image_button::cache_path()
{
    return m_path.c_str();
}

